﻿namespace Sidvall.IdentityManager.Net.SimpleServices.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class ServerItem : global::Sidvall.Data.SimpleServiceDataRowBase, global::Sidvall.IdentityManager.Data.IServerItem
    {
        #region Public Members

        #region ConnectionString

        private string _ConnectionString;
        public string ConnectionString
        {
            get
            {
                return _ConnectionString;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_ConnectionString, value))
                    return;
                _ConnectionString = value;
                OnPropertyChanged(nameof(ConnectionString), true);
            }
        }

        #endregion
        #region ConnectionTypeId

        private global::Sidvall.IdentityManager.Data.ConnectionType _ConnectionTypeId;
        public global::Sidvall.IdentityManager.Data.ConnectionType ConnectionTypeId
        {
            get
            {
                return _ConnectionTypeId;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_ConnectionTypeId, value))
                    return;
                _ConnectionTypeId = value;
                OnPropertyChanged(nameof(ConnectionTypeId), true);
            }
        }

        #endregion
        #region Name

        private string _Name;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_Name, value))
                    return;
                _Name = value;
                OnPropertyChanged(nameof(Name), true);
            }
        }

        #endregion
        #region RemoteAddress

        private string _RemoteAddress;
        public string RemoteAddress
        {
            get
            {
                return _RemoteAddress;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_RemoteAddress, value))
                    return;
                _RemoteAddress = value;
                OnPropertyChanged(nameof(RemoteAddress), true);
            }
        }

        #endregion
        #region ServerItemId

        private System.Nullable<int> _ServerItemId;
        public System.Nullable<int> ServerItemId
        {
            get
            {
                return _ServerItemId;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_ServerItemId, value))
                    return;
                _ServerItemId = value;
                OnPropertyChanged(nameof(ServerItemId), true);
            }
        }

        #endregion
        #region STSAddress

        private string _STSAddress;
        public string STSAddress
        {
            get
            {
                return _STSAddress;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_STSAddress, value))
                    return;
                _STSAddress = value;
                OnPropertyChanged(nameof(STSAddress), true);
            }
        }

        #endregion
        #region STSClientId

        private string _STSClientId;
        public string STSClientId
        {
            get
            {
                return _STSClientId;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_STSClientId, value))
                    return;
                _STSClientId = value;
                OnPropertyChanged(nameof(STSClientId), true);
            }
        }

        #endregion
        #region STSClientSecret

        private string _STSClientSecret;
        public string STSClientSecret
        {
            get
            {
                return _STSClientSecret;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_STSClientSecret, value))
                    return;
                _STSClientSecret = value;
                OnPropertyChanged(nameof(STSClientSecret), true);
            }
        }

        #endregion
        #region TwoFactorProvider

        private System.Nullable<Sidvall.Security.TwoFactorProvider> _TwoFactorProvider;
        public System.Nullable<Sidvall.Security.TwoFactorProvider> TwoFactorProvider
        {
            get
            {
                return _TwoFactorProvider;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_TwoFactorProvider, value))
                    return;
                _TwoFactorProvider = value;
                OnPropertyChanged(nameof(TwoFactorProvider), true);
            }
        }

        #endregion
        #region UserConfigurationId

        private int _UserConfigurationId;
        public int UserConfigurationId
        {
            get
            {
                return _UserConfigurationId;
            }
            set
            {
                if (Sidvall.Business.ValidationManager.IsEqual(_UserConfigurationId, value))
                    return;
                _UserConfigurationId = value;
                OnPropertyChanged(nameof(UserConfigurationId), true);
            }
        }

        #endregion
        
        public UserConfiguration UserConfiguration { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public PluginCollection Plugins { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade)
        {
            global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.LoadInstanceField(this, fieldName, value, cascade, false, false);
        }

        #endregion
        #region Copy

        public ServerItem Copy()
        {
            return global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Copy(this);
        }
        public ServerItem Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IServerItem item)
        {
            global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Import(this, item);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IServerItem item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Initialize(this, settings);
        }

        #endregion

        #region IServerItem Members

        string global::Sidvall.IdentityManager.Data.IServerItem.ConnectionString
        {
            get
            {
                return this._ConnectionString;
            }
            set
            {
                this._ConnectionString = value;
            }
        }
        global::Sidvall.IdentityManager.Data.ConnectionType global::Sidvall.IdentityManager.Data.IServerItem.ConnectionTypeId
        {
            get
            {
                return this._ConnectionTypeId;
            }
            set
            {
                this._ConnectionTypeId = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IServerItem.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IServerItem.RemoteAddress
        {
            get
            {
                return this._RemoteAddress;
            }
            set
            {
                this._RemoteAddress = value;
            }
        }
        System.Nullable<int> global::Sidvall.IdentityManager.Data.IServerItem.ServerItemId
        {
            get
            {
                return this._ServerItemId;
            }
            set
            {
                this._ServerItemId = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IServerItem.STSAddress
        {
            get
            {
                return this._STSAddress;
            }
            set
            {
                this._STSAddress = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IServerItem.STSClientId
        {
            get
            {
                return this._STSClientId;
            }
            set
            {
                this._STSClientId = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IServerItem.STSClientSecret
        {
            get
            {
                return this._STSClientSecret;
            }
            set
            {
                this._STSClientSecret = value;
            }
        }
        System.Nullable<Sidvall.Security.TwoFactorProvider> global::Sidvall.IdentityManager.Data.IServerItem.TwoFactorProvider
        {
            get
            {
                return this._TwoFactorProvider;
            }
            set
            {
                this._TwoFactorProvider = value;
            }
        }
        int global::Sidvall.IdentityManager.Data.IServerItem.UserConfigurationId
        {
            get
            {
                return this._UserConfigurationId;
            }
            set
            {
                this._UserConfigurationId = value;
            }
        }
        global::Sidvall.IdentityManager.Data.IUserConfiguration global::Sidvall.IdentityManager.Data.IServerItem.UserConfiguration
        {
            get
            {
                return this.UserConfiguration;
            }
            set
            {
                this.UserConfiguration = (UserConfiguration)value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.IdentityManager.Data.IPlugin> global::Sidvall.IdentityManager.Data.IServerItem.Plugins
        {
            get
            {
                if (this.Plugins != null)
                    return this.Plugins;
                return null;
            }
        }
        void global::Sidvall.IdentityManager.Data.IServerItem.SetPlugins(Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IPlugin> items)
        {
            this.Plugins = (PluginCollection)items;
        }

        #endregion

        #endregion
        #region Constructors

        public ServerItem()
        {
        }
        public ServerItem(bool initializeDefaultValues)
        {
            if (initializeDefaultValues)
                global::Sidvall.IdentityManager.SystemContextConfig.Current.EntityFacade.ServerItemManager.Initialize(this);
        }

        #endregion
    }
}